import scala.beans.BeanProperty

class Counter {
  private var value = 0

  def increment(): Unit = {
    if (value < Int.MaxValue) value += 1
  }

  def current: Int = value
}

class BankAccount {
  private[this] var account: Double = 0

  def deposit(value: Double): Unit = {
    this.account += value
  }

  def withdraw(value: Double): Unit = {
    if (value <= account)
      account -= value
    else
      throw new Exception("Your balance (" + account + ") too small to withdraw " + value)
  }

  def balance: Double = account
}

class Time1(val h: Int, val m: Int) {
  if (h >= 24 || h < 0) throw new ExceptionInInitializerError("0 <= hrs <= 23")
  if (m >= 60 || m < 0) throw new ExceptionInInitializerError("0 <= min <= 59")

  def before(other: Time1): Boolean = h * 60 + m < other.h * 60 + other.m
}

class Time2(val h: Int, val m: Int) {
  if (h >= 24 || h < 0) throw new ExceptionInInitializerError("0 <= hrs <= 23")
  if (m >= 60 || m < 0) throw new ExceptionInInitializerError("0 <= min <= 59")

  private val mins: Int = h * 60 + m

  def before(other: Time2): Boolean = this.mins < other.mins
}

class Student(@BeanProperty var name: String, @BeanProperty var id: Long)

class Person1(var age: Int) {
  if (age < 0) age = 0
}

// scalac 05.scala
// javap -private Student

class Person2(fullName: String) {
  val firstName: String = fullName.split("\\s+")(0)
  val lastName: String = fullName.split("\\s+")(1)

  override def toString: String = {
    s"Person($firstName, $lastName)"
  }
}

class Car(val manufacturer: String, val modelName: String, val modelYear: Int = -1, var licensePlate: String = "") {
  def this(manufacturer: String, modelName: String, modelYear: Int) {
    this(manufacturer, modelName, modelYear, "")
  }

  def this(manufacturer: String, modelName: String, licensePlate: String) {
    this(manufacturer, modelName, -1, licensePlate)
  }

  def this(manufacturer: String, modelName: String) {
    this(manufacturer, modelName, "")
  }
}

class Employee(val name: String = "John Q. Public", var salary: Double = 0.0)

object Sheet5 {
  def main(args: Array[String]): Unit = {
    val student = new Student("A", 1)
    println(student.getName)
  }
}